/**
 * Copyright (C) 2012 51Degrees.mobi Limited
 *
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Affero General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or (at your
 * option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License
 * for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */


#include <stdio.h>
#include <string.h>

#include "51Degrees.mobi.h"

#define BUFFER_LENGTH 50000

int main(int argc, char* argv[]) {
	Workset *ws = NULL;
	char output[BUFFER_LENGTH];
	const Device *device;

	int initRes = init(argc > 1 ? argv[1] : "Id");
	if (initRes == 0) {
		ws = createWorkset();

		gets(ws->input);
		while(strlen(ws->input) > 0) {
			device = getDevice(ws);
			if (device != NULL) {
				processDeviceCSV(device, output, BUFFER_LENGTH);
				printf("%s", output);
			}
			else {
				printf("null\n");
			}

			// Flush buffers.
			fflush(stdin);
			fflush(stdout);

			// Get the next useragent.
			gets(ws->input);
		}

		freeWorkset(ws);
		destroy();
	}
	return initRes;
}


